//
//  CMDBPublishPhotosView.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/19.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBPublishPhotosController: NormalTitleViewController {
    
    lazy var images : [UIImage] = {
        
        var images = [UIImage]()
        
        return images
    
    }()
    
    private lazy var popoverAnimator : PopoverAnimator = PopoverAnimator {[weak self] (presented) -> () in
        self!.upButton.selected = presented
    }
    
    var upButton : UIButton!
    
    var addCollectionView : CMDBAddAlbumCollectionView? = CMDBAddAlbumCollectionView.getInstance()
    
    override func buildTitleView() {
        super.buildTitleView()
        
        let button                    = UIButton(frame : CGRect(x: CMDB_Screen_Width - 140, y: 0, width: 100, height: 64))
        
        upButton                    = button
        
        button.selected             = false
        
        button.center                 = CGPoint(x: CMDB_Screen_Width - 20, y: self.titleView!.middleY + 10)
        
        button.setTitle("上传", forState: .Normal)
        
        button.titleLabel?.font       = CMDB_16_FONT
        
        button.setTitleColor(UIColor.lightGrayColor(), forState: .Normal)
        
        self.titleView?.addSubview(button)
        
        button.addTarget(self, action: #selector(sendItemClick), forControlEvents: .TouchUpInside)
    }
    
    override func buildContentView() {
        super.buildContentView()
        
        addCollectionView!.mDelegate  = self
        
        addCollectionView!.frame      = CGRect(x: 0, y: 0, width: CMDB_Screen_Width, height: contentView!.height)
        
        contentView?.addSubview(addCollectionView!)
        
        addCollectionView!.images     = images
        
        contentView?.backgroundColor  = UIColor.cyanColor()
    }
    
    override func popSelf() {
        dismissViewControllerAnimated(true, completion: nil)
    }
}

//MARK: - action method
extension CMDBPublishPhotosController{
    
    @objc func sendItemClick(){
        
        printLog("sendItem")
        
        let popViewController = CMDBAlbumsViewController()
        
        popoverAnimator.isPusblish = false
        
        popViewController.modalPresentationStyle = .Custom
        
        popViewController.transitioningDelegate = popoverAnimator
        
        popoverAnimator.presentedFrame = CGRect(x: 0.2 * CMDB_Screen_Width, y: 0, width: 0.8 * CMDB_Screen_Width, height: CMDB_Screen_Height)
        
        presentViewController(popViewController, animated: true, completion: nil)
        
    }
}


extension CMDBPublishPhotosController{
    
    override func onItemClickType(itemClickType: String?, data: AnyObject?, indexPath: NSIndexPath?) {
        
        let itemType = ItemClickType(string:itemClickType!)
        
        switch itemType {
        case .AddPhotoClick:
            printLog("AddPhotoClick")
        default:
            printLog("default")
        }
    }
    
}
